var Basic=require("../Model/Basic.js");
function BasicControll(app,Mysql)
{
	var BasicModel=Object.create(Basic.BasicModel);
	app.post('/basic/setroomtype', SetRoomType);
	app.post('/basic/sethotelroom', SetHotelRoom);
	app.post('/basic/sethotel', SetHotel);
	app.get('/basic/gethotels', GetHotels);
	app.get('/basic/getroomtype', GetRoomType);
	app.get('/basic/gethotelroombytype', GetHotelRoomByType);

	function SetHotel(req, res, next) {
		var Hotel=new Object();
		Hotel.iCode=req.body.code;
		Hotel.iName=req.body.name;
		Hotel.iAddr=req.body.addr;
		BasicModel.SetHotel(Mysql,Hotel,function(Data)
		{
			res.json(Data);
		});
	}

	function GetHotels(req, res, next) {
		BasicModel.GetHotels(Mysql,function(Data)
		{
			res.json(Data);
		});
	}

	function SetRoomType(req, res, next) {
		var RoomType=new Object();
		RoomType.iCode=req.body.code;
		RoomType.iTypeId=req.body.typeid;
		RoomType.iTypeName=req.body.name;
		if(RoomType.iTypeId==0)
		{
			BasicModel.NewRoomType(Mysql,RoomType,function(Data)
			{
				res.json(Data);
			});
		}else if(RoomType.iTypeId>0)
		{
			BasicModel.UpdateTypeName(Mysql,RoomType,function(Data)
			{
				res.json(Data);
			});
		}else{
			var TypeId=RoomType.iTypeId*(-1);
			BasicModel.DeleteRoomType(Mysql,TypeId,function(Data)
			{
				res.json(Data);
			});
		}
	}

	function GetRoomType(req, res, next) {
		var Code=req.query.code;
		BasicModel.GetRoomType(Mysql,Code,function(Data)
		{
			res.json(Data);
		});
	}

	function SetHotelRoom(req, res, next) {
		var Code=req.body.code;
		var Room=new Object();
		Room.iRoomNo=req.body.room;
		Room.iRoomType=req.body.typeid;
		BasicModel.SetHotelRoom(Mysql,Code,Room,function(Data)
		{
			res.json(Data);
		});
	}

	function GetHotelRoomByType(req, res, next) {
		var Code=req.query.code;
		var TypeId=req.query.typeid;
		BasicModel.GetHotelRoomByType(Mysql,Code,TypeId,function(Data)
		{
			res.json(Data);
		});
	}
}
exports.BasicControll=BasicControll;